package com.taozi.web.controller.question;

import com.taozi.common.annotation.Log;
import com.taozi.common.core.controller.BaseController;
import com.taozi.common.core.domain.AjaxResult;
import com.taozi.common.core.page.TableDataInfo;
import com.taozi.common.enums.BusinessType;
import com.taozi.common.utils.poi.ExcelUtil;


import com.taozi.question.domain.QuestionInfo;
import com.taozi.question.service.IQuestionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 问题详情Controller
 *
 * @author taozi
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/system/info")
public class QuestionInfoController extends BaseController {
    @Autowired
    private IQuestionInfoService questionInfoService;

    /**
     * 查询问题详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuestionInfo questionInfo)
    {
        startPage();
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        return getDataTable(list);
    }

    /**
     * 导出问题详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "问题详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuestionInfo questionInfo)
    {
        List<QuestionInfo> list = questionInfoService.selectQuestionInfoList(questionInfo);
        ExcelUtil<QuestionInfo> util = new ExcelUtil<QuestionInfo>(QuestionInfo.class);
        util.exportExcel(response, list, "问题详情数据");
    }

    /**
     * 获取问题详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(questionInfoService.selectQuestionInfoById(id));
    }

    /**
     * 新增问题详情
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "问题详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody QuestionInfo questionInfo)
    {
        return toAjax(questionInfoService.insertQuestionInfo(questionInfo));
    }

    /**
     * 修改问题详情
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "问题详情", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody QuestionInfo questionInfo)
    {
        return toAjax(questionInfoService.updateQuestionInfo(questionInfo));
    }

    /**
     * 删除问题详情
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "问题详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(questionInfoService.deleteQuestionInfoByIds(ids));
    }
}
